home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
image.ed
/
main10.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-26
|
14KB
|
440 lines
/************* main10.c ******************/
/* we will show 9 views totally as a 3 by 3 matrix ..... if there are
* more, we will scroll them into view, thunk! thunk! etc., showing
* 9 at a time, in a fixed space.
*/
#include "intuall.h"
#include "imageedit.h"
#define SECONDS io_Actual
#define MICROSECONDS io_Length
extern SHORT zeros[];
extern struct Menu menu[];
extern SHORT palette[];
extern SHORT depth;
struct frame f[MAXVIEWS];
SHORT selected; /* which frame number is cursor in? */
extern struct TextAttr TestFont;
extern struct Requester myrequest;
extern BYTE dosname[];
long GfxBase = 0;
SHORT framewidth, frameheight, editbottom, editright;
SHORT bobdepth;
struct Window *OpenWindow();
struct InputEvent *Intuition();
struct Screen *OpenScreen();
struct RastPort *CDRastPort();
extern struct MsgPort *CreatePort();
extern struct IOStdReq *CreateStdIO();
struct MsgPort *timerport; /* for timer communications */
struct IOStdReq *timermsg; /* for timer */
SHORT click, timeout; /* use of these variables to prevent the
* holding down of the mouse from accidently
* selecting an alternate frame if the user
* has moved the mouse into an alternate frame
* without first lifting the left button */
ULONG wakeupbit; /* timer bit or event bit wake us up? */
USHORT class;
USHORT code;
USHORT qualifier;
USHORT mode; /* mode of operation */
APTR address; /* address of the gadget which we hit */
struct Window *w;
struct Screen *screen;
struct RastPort *rp;
struct ViewPort *vp;
struct IntuiMessage *message;
extern HandleEvent();
long IntuitionBase=0;
struct NewScreen ns = {
0, 0, /* start position */
640, 200, DEPTH, /* width, height, depth */
0, 1, /* detail pen, block pen */
HIRES, /* viewing mode */
CUSTOMSCREEN, /* screen type */
&TestFont, /* font to use */
"Image Editor, v1.0", /* default title for screen */
NULL /* pointer to additional gadgets */
};
struct NewWindow nw = {
0, 0, /* start position */
640, 200, /* width, height */
0, 1, /* detail pen, block pen */
GADGETUP | GADGETDOWN | MOUSEBUTTONS | MENUPICK | RAWKEY,
/* IDCMP flags */
ACTIVATE | BACKDROP | BORDERLESS,
/* window flags */
NULL, /* pointer to first user gadget */
NULL, /* pointer to user checkmark */
NULL, /* window title */
NULL, /* pointer to screen (later) */
NULL, /* pointer to superbitmap */
0,0,0,0, /* ignored/not a sized window so
* dont have to specify min/max
* size to allow */
CUSTOMSCREEN /* type of screen in which to open */
};
main()
{
SHORT i,condition;
BYTE *s, *d, *defaultname;
depth = DEPTH;
for(i=0; i<20; i++)
zeros[i]=0;
condition = TRUE;
/* here going to establish the values for editright and editbottom
* for the reconfiguring of the editor
*/
bobdepth = BOBDEPTH;
framewidth = FRAMEWIDTH; /* establish the defaults */
frameheight = FRAMEHEIGHT;
editright = EDITLEFT + 4 * framewidth;
editbottom = EDITTOP + 4 * frameheight;
/* the prior 2 equations will be used during reconfigure */
GfxBase = OpenLibrary("graphics.library", 0);
if (GfxBase == NULL)
{
printf("Unable to open graphics library\n");
exit(1000);
}
IntuitionBase = OpenLibrary("intuition.library", 0);
if (IntuitionBase == NULL)
{
printf("Unable to open intuition library\n");
exit(1000);
}
timerport = CreatePort(0,0);
if (timerport == 0) { exit(997); }
timermsg = CreateStdIO(timerport);
if (timermsg == 0) { exit(996); }
if (condition)
{
screen = OpenScreen(&ns);
if (screen == NULL)
{
exit(1);
}
nw.Screen = screen;
w = OpenWindow(&nw); /* open a window */
rp = w->RPort;
vp = &w->WScreen->ViewPort;
/* Set the color registers Black, Red, Green, Blue, Yellow, Magenta,
Cyan, White */
if(palette[DEPTH-1] == 8)
{
SetRGB4(vp,0,00,00,00);
SetRGB4(vp,1,15,00,00);
SetRGB4(vp,2,00,15,00);
SetRGB4(vp,3,00,00,15);
SetRGB4(vp,4,15,15,00);
SetRGB4(vp,5,15,00,15);
SetRGB4(vp,6,00,15,15);
SetRGB4(vp,7,15,15,15);
}
else if (palette[DEPTH-1] == 16)
{
/* black, black, white, fireengine red, orange, yellow,
lime green, green, aqua, dark blue, purple,
violet, tan, brown, gray, skyblue */
SetRGB4(vp,0,00,00,00);
SetRGB4(vp,1,14,3,0);
SetRGB4(vp,2,15,15,15);
SetRGB4(vp,3,11,4,0);
SetRGB4(vp,4,15,11,0);
SetRGB4(vp,5,11,15,0);
SetRGB4(vp,6,5,13,0);
SetRGB4(vp,7,0,14,13);
SetRGB4(vp,8,7,13,15);
SetRGB4(vp,9,6,9,15);
SetRGB4(vp,10,12,0,14);
SetRGB4(vp,11,15,2,14);
SetRGB4(vp,12,15,13,11);
SetRGB4(vp,13,12,9,8);
SetRGB4(vp,14,11,11,11);
SetRGB4(vp,15,7,13,15);
}
}
else
{
exit(); /* couldn't close workbench */
}
/* ******************************************************************* */
InitMenu();
InitDosRequest(); /* only mods to main3.c */
InitDosText(); /* only mods to main3.c */
InitTextRequest();
InitNewColorText();
InitColorRequest();
defaultname = "images";
s = defaultname;
d = &dosname[0];
while((*d++ = *s++) != '\0')
; /* copy name into buffer */
/* mods between here an InitDosRequest above */
/* ******************************************************************* */
/* PrepareMenuStrip(); *** new format of strip init */
/* Set up the Menu bar */
if (!(SetMenuStrip(w, &menu[0])))
{
CloseWindow(w);
CloseScreen(screen);
exit(998);
}
/* Initialize the timer */
if (init_timer() != 0)
{
CloseWindow(w);
CloseScreen(screen);
exit(1);
}
SetAPen(rp,2);
SetDrMd(rp,JAM1);
initoutlines();
workbitmaps(); /* init the work bit maps for expansion */
ShowTitle(screen,TRUE);
class=0; code =0; /* initialize */
/* Wait for a CLOSEWINDOW */
set_timer(0,70000);
/* 70,000 microseconds = .07 sec */
do {
click = FALSE; timeout = FALSE;
message = (struct IntuiMessage *)GetMsg(w->UserPort);
if(message == NULL) /* EMPTY THE PORT!!!!!, if intuition
* sent us two messages, both would
* have set the same signal bit....
* so we must respond to all messages
* rather than simply checking if
* a signal bit was set.
* (earlier version of program
* got stuck one message behind
* while responding to prior msg
* and simply going to sleep
* without emptying the port first
*/
{
wakeupbit = Wait( 1 << w->UserPort->mp_SigBit
| 1 << timerport->mp_SigBit );
/* go to sleep waiting for click or timeout or both */
/* if receive an intuion message, save its variables and reply
* (make the message available for reuse by Intuition) */
if( wakeupbit & (1 << w->UserPort->mp_SigBit ))
{
click = TRUE;
message = (struct IntuiMessage *)GetMsg(w->UserPort);
if(message != NULL)
{
class = message->Class;
code = message->Code;
qualifier = message->Qualifier;
address = message->IAddress;
ReplyMsg(message);
}
}
/* if wakened by a timeout, it may be time to write another
* dot. After each timeout, restore the time variables,ask to
* start another timing interval */
if( wakeupbit & (1 << timerport->mp_SigBit ))
{
GetMsg(timerport);
timeout = TRUE;
set_timer(0,70000);
}
}
else /* this empties the port if more than
* one message arrives with a single
* signal bit
*/
{
class = message->Class;
code = message->Code;
qualifier = message->Qualifier;
address = message->IAddress;
ReplyMsg(message);
}
} while (HandleEvent()); /* keep going as long as handleevent
* returns a true value */
CloseWindow(w);
CloseScreen(screen);
FreeMyMemory(); /* give back all allocated rasters to system */
DeleteStdIO(timermsg);
DeletePort(timerport);
}
init_timer()
{
return( OpenDevice(TIMERNAME,UNIT_VBLANK,timermsg,0));
}
set_timer(sec,micro)
ULONG sec,micro;
{
timermsg->io_Command = TR_ADDREQUEST; /* add a new timer request */
timermsg->SECONDS = sec; /* seconds */
timermsg->MICROSECONDS = micro; /* microseconds */
SendIO( timermsg ); /* post a request to the timer */
return(0);
}
/* user has put the left button of the mouse down somewhere. We must
* a. write a big pixel if he is in the edit window.
* b. select another window and copy its contents to the
* big window for editing (only if button lifted first)
* c. do nothing (for now) if he is outside of all windows.
*
*/
doclick(x,y)
SHORT x,y;
{
SHORT i;
if(qr(x,EDITLEFT,editright-1) && qr(y,EDITTOP,editbottom-1))
{
bigpixel(x,y);
WritePixel(rp,f[selected].xmin+((x-EDITLEFT) >> 2),
f[selected].ymin+((y-EDITTOP) >> 2) );
return(0);
}
if( timeout == FALSE )
{
for(i=0; i<MAXVIEWS; i++)
if(qr(x,f[i].xmin,f[i].xmax) && qr(y,f[i].ymin,f[i].ymax))
{ select(&f[i],i); break; }
}
return(0);
}
select(p,i) /* select a new object to work with */
struct frame *p;
SHORT i;
{
struct frame *q; /* deselect the previous box */
if( i == selected ) return(0); /* dont erase if same one selected twice */
erase_edit();
q = &f[selected];
box(q->xmin-1, q->ymin-1, q->xmax+2, q->ymax+2, 7);
selected = i;
box(p->xmin-1, p->ymin-1, p->xmax+2, p->ymax+2, 2);
doexpand(i);
return(0);
}
box(x,y,xh,yh,c)
SHORT x,y,xh,yh,c;
{
SHORT oldpen;
oldpen = rp->FgPen;
SetAPen(rp,c);
Move(rp,x,y); Draw(rp,x,yh); Draw(rp,xh,yh); Draw(rp,xh,y);
Draw(rp,x,y);
SetAPen(rp,oldpen);
return(0);
}
erase_edit() /* clear the edit window */
{
SHORT oldpen;
oldpen = rp->FgPen;
SetAPen(rp,0);
SetDrMd(rp,JAM1);
RectFill(rp,EDITLEFT,EDITTOP,editright+2,editbottom+2);
box(EDITLEFT-1, EDITTOP-1, editright+1, editbottom+1,7);
SetAPen(rp,oldpen);
return(0);
}
initoutlines()
{
SHORT i,j,k;
SHORT x,y;
k=0;
y=23;
for(i=0; i<3; i++)
{
x = editright+9;
for(j=0; j<3; j++)
{
box(x,y,x+framewidth+2,y+frameheight+2,7);
f[k].xmin = x+1;
f[k].ymin = y+1;
f[k].xmax = x+framewidth;
f[k].ymax = y+frameheight;
x += framewidth+16;
k++;
}
y += frameheight+8;
}
selected = 0; /* force first one to get highlighted */
select(&f[0],0); /* highlight the first one */
SetAPen(rp,0);
erase_edit();
box(f[0].xmin-1, f[0].ymin-1, f[0].xmax+2, f[0].ymax+2, 2);
return(0);
}